package com.qf.web.controller;

import com.qf.web.common.request.BannerRequestParams;
import com.qf.web.common.result.ResponseResult;
import com.qf.web.service.BannerService;
import com.qf.web.service.UploadService;
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author zhangwei
 * 1. 添加轮播图
 * 2. 修改
 * 3 分页查询列表
 * 4 查看详细信息
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Resource
    BannerService bannerService;
    @Resource
    private UploadService uploadService;

    /**
     * 业务命名
     * body  name=1&description=1111
     *
     * @return {
     * "name": "1",
     * "description": "111111"
     * }
     * <p>
     * <p>
     * <p>
     * <p>
     * <p>
     * {
     * "name": "",
     * "description": "",
     * "img": "",
     * "linkStatus": 0,
     * "link": 0,
     * "linkJump": 0,
     * "productId": 0,
     * "type": 0,
     * "createDate": 1647226949648
     * <p>
     * 文件上传
     * 日期
     * 上传日期
     * 客服端上传字符串  转化成日期格式  建议不要使用数据库的转化,在业务程序中转化
     * "2022-03-14"
     * 在json数据序列化框架中配置
     * }
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@Validated(BannerRequestParams.Add.class) @RequestBody BannerRequestParams banner) {
        int count = bannerService.add(banner);
        return ResponseResult.success(count);
    }

    /**
     * 文件上传
     * 1. 上传的本地的服务器
     * <p>
     * 2. 上传到云对象存储  OSS
     * <p>
     * 3  FastDFS  (技术要求高)
     * 文件上传加上
     * 接收客服端json数据转化
     *
     * @return
     */
    @PostMapping("/upload/img")
    public ResponseResult<String> uploadImage(@RequestBody MultipartFile multipartFile) {
        String url = uploadService.uploadImage(multipartFile);
        return ResponseResult.success(url);
    }

    @PutMapping("/mod")
    public ResponseResult<String> mod(BannerRequestParams banner) {
        return null;
    }
}
